package com.genreate.util.pay.ali.app;

import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.ApiResponse;
import com.alipay.v3.Configuration;
import com.alipay.v3.util.GenericExecuteApi;
import com.alipay.v3.util.model.AlipayConfig;
import com.alipay.v3.util.model.CustomizedParams;
import com.alipay.v3.util.model.OpenApiGenericRequest;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GenericExecute {

    public static void main(String[] args) throws ApiException {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        // 初始化alipay参数（全局设置一次）
        defaultClient.setAlipayConfig(getAlipayConfig());

        GenericExecuteApi api = new GenericExecuteApi();

        // 构造请求参数以调用接口
        Map<String, Object> bizParams = new HashMap<>();
        Map<String, Object> bizContent = new HashMap<>();
        
        // 设置商户订单号
        bizContent.put("out_trade_no", "XS202507080001");
        
        // 设置订单总金额
        bizContent.put("total_amount", "9.00");
        
        // 设置订单标题
        bizContent.put("subject", "测试标题");
        
        // 设置订单附加信息
        bizContent.put("body", "订单附加信息");
        
        // 设置订单绝对超时时间
        bizContent.put("time_expire", "2025-12-31 10:05:00");
        
        // 设置禁用渠道
        bizContent.put("disable_pay_channels", "pcredit,moneyFund,debitCardExpress");
        
        bizParams.put("biz_content", bizContent);

        try {
            // 如果是第三方代调用模式，请设置app_auth_token（应用授权令牌）
            String orderStr = api.sdkExecute("alipay.trade.app.pay", bizParams, null, "<-- 请填写应用授权令牌 -->", null);
            System.out.println(orderStr);
        } catch (ApiException e) {
            System.out.println("调用失败");
        }
    }

    private static AlipayConfig getAlipayConfig() {
        AlipayConfig alipayConfig = new AlipayConfig();
//        alipayConfig.setServerUrl("https://openapi.alipay.com");
        alipayConfig.setServerUrl("https://openapi.alipaydev.com/gateway.do");
        alipayConfig.setAppId("9021000135622741");
        alipayConfig.setPrivateKey("MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCjw4Iqs0Xf8cZD2HGJqVK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GSbvlVW4ydvS4lDHCVTPAY9ux1Y2B2J86MpMyg7X4fkPMZDgwEaczYr2doO+a5amHnPqvqRnBxFXSzLbAefP3tnmY+7lBMbpy53EhEYqmPTB19z1FSDGJrbqV4xAoGAOY6zdPf6lX467xwroWxz1OAJdZXtMK+ATps0KGYWNdEP/jj8pmYLHRPaqv4l+GNcj8yuYLPeO+KtbaxI8VjY/P0SoOwCUB5xswb6Lu7qFQHcNr9gaslldVXhKBdBearfpjtHoVqK4+da6BTnMth2dqAyhOMLEljwZfxBWWRT6gkCgYBsUknObPmJx+Fczrxe4Q/scRkRBD9o0sLbzw3oXxoqOmcwlDfIN8aukWIxeAvmBvivIP7OYLbRWtkG49ie41HCBlSyo7S43RHMWAZwOnjw9/C4jYIK0im3D12jY1jWBoWHcCgNKw5pB2bR7g9rcGFqdYasV10apoScTcexXt7cqQ==");
        alipayConfig.setAlipayPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo9O9XO8bswch8zVMY2lLM4187QDSzXsPJ0d7x1Nco1xJCuRHdft4AiHxrUeObatwgzwK1ZWddOHNwwWODas+9V7Jg1geqySW9vHlHKgnXksPzWQGjvIyxkQZ/bCcDE4YqWFYWoHDXq54a3Il4aTpCXyY97jax141R/n1Ba+/eGbaRJ0qFfOfucI+ZCSGdCoE95GGr5Q6R88k6ui+hVRaTS8IgQcolUUQT0trnH7oE09iE6TZlCEApYQ4iAvHlz2/8on8NYYHxvONq1qIrqIcAEBYbTNzEaDMjAS9wPa6qwjIk0fkyWUDh64XyvOa50lev93r9h3xA1/nXNOKuWZ6pwIDAQAB");
        return alipayConfig;
    }
}